class TalkDialog extends renderer.DisplayObjectContainer {


    titleText: renderer.TextField;
    contentText: renderer.TextField;
    contentTexts: renderer.TextField[] = [];
    private mission: Mission;
    background: renderer.Bitmap;
    private npc: Npc;
    dialogNpc: renderer.Bitmap;
    private i = 0;

    imageId = 0;
    imageUrls: string[] = [];
    npcDialogTexture = new Image();

    constructor(npc1: Npc) {
        super();

        const dialogBackgroundTexture = new Image();
        dialogBackgroundTexture.src = 'dialog.png';

        const background = new renderer.Bitmap(0, 416, dialogBackgroundTexture);

        this.imageUrls = npc1.imageUrls;
        // const npcDialogTexture = new Image();
        // npcDialogTexture.src = this.imageUrls[this.i];
        const dialogNpc = new renderer.Bitmap(0, 128, this.npcDialogTexture);


        // background.scaleX = background.scaleY = .5;
        // this.removeAllChildren();

        this.addChild(dialogNpc);
        this.addChild(background);

        this.titleText = new renderer.TextField();
        //this.addChild(this.titleText);
        this.titleText.x = this.titleText.y = 100;

        this.contentText = new renderer.TextField();
        this.addChild(this.contentText);
        this.contentText.x = 80;
        this.contentText.y = 464;


        this.addEventListener("click", (eventData: any) => {
            this.i++;
            this.update();
        });
        // this.addEventListener("click", () => {
        //     this.dispatchEvent('changelihui', {});
        // });
        // background.addEventListener("toolinformation", () => {
        //     this.addChild(background);
        // })
    }

    update() {
        const mission = this.mission;
        let content = ""
        let contents: string[];

        if (this.mission) {
            this.titleText.text = this.mission.name;


            if (this.mission.status == MissionStatus.CAN_ACCEPT) {

                contents = this.mission.contents;


            }
            else if (this.mission.status == MissionStatus.CAN_SUBMIT) {
                // content = this.mission.canSubmitContent
                contents = [];


            }
            else {
                contents = [];
            }
            if (this.i >= contents.length) {
                this.dispatchEvent("close", null);
            } else {
                this.contentText.text = contents[this.i];
                this.imageId = mission.images[this.i];

                const npcImage = npcImageManager.getNpcImageById(this.imageId);
                if (npcImage) {
                    this.npcDialogTexture.src = npcImage.imageUrl;
                }

            }
        }


    }

    setMission(mission: Mission, npc: Npc) {
        this.mission = mission;
        this.npc = npc;
        this.update();
    }




}